<?php
/**
 * Copyright 2012  SURFfoundation
 * 
 * This file is part of ESCAPE.
 * 
 * ESCAPE is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * ESCAPE is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with ESCAPE.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * For more information:
 * http://escapesurf.wordpress.com/
 * http://www.surffoundation.nl/
 * 
 * Contact: d.vierkant@utwente.nl
 * 
 * @license http://www.gnu.org/licenses/gpl.html GNU GPLv3
 */
?>
<?php
require_once("config/escape.inc.php");
require_once("escape/include.php");

// PHP4 code in the OAI library causes a lot of warnings
error_reporting(E_ALL ^ E_COMPILE_WARNING ^ E_NOTICE ^ E_WARNING ^ E_DEPRECATED);

// include the PEAR base class
require_once('PEAR.php');

// include the OAI Server
require_once('OAI/Server.php');

// include the server backend class
require_once('escape/repository/OaiServerBackend.php');

// set the options for the OAI Server
$serverOptions = array(
	'repository_name' => $escape_config['rem_creator_name'],
	'repository_identifier' => $escape_config['oai_repository_identifier'],
	'friends' => null,
	'admin_emails' => array($escape_config['admin_email']),

	'deleted_record' => 'persistent',
	
	'masquerade' => true,
	
	'listrecords_max' => 100,
	'listidentifiers_max' => 100,
	
	'metadata_formats' => array(
		'oai_dc' => array(
							'schema' => 'http://www.openarchives.org/OAI/2.0/oai_dc.xsd',
							'namespace' => 'http://www.openarchives.org/OAI/2.0/oai_dc/'
		),
		'oai_ore' => array(
							'schema' => 'http://www.w3.org/2000/07/rdf.xsd',
							'namespace' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'
		)
	)
);

// instantiate OAI server
$oai_server =& new OAI_Server($serverOptions);

// instantiate the ESCAPE repository
$repository = new escape_repository_Repository($escape_config);

// open the connection to the ESCAPE repository
$repository->initialize();

// set the server backend options
$backendOptions = array(
	'sets' => $escape_config['oai_sets'],
);

// instantiate the server backend
$backend = new escape_repository_OaiServerBackend($backendOptions, $repository);
$oai_server->backend($backend);

// display the response to the OAI request
$oai_server->response();

// close the connection to the ESCAPE repository
$repository->shutdown();
